import { routes } from '../../router/index'
import { RouteRecordRaw } from 'vue-router'
interface StateValue {
  topRouteName: string;
  secondRouteName: string;
  thirdRouteName: string;
}
export default {
  state: {
    topRouteName: '',
    secondRouteName: '',
    thirdRouteName: ''
  },
  getters: {
    articleList: (state: StateValue): RouteRecordRaw[] => {
      if (state.topRouteName === '' || state.secondRouteName === '') return []
      const secondRoutes: RouteRecordRaw[] = (routes.find((route: RouteRecordRaw) => route.name === state.topRouteName) as any).children
      const thirdRoute: RouteRecordRaw[] = (secondRoutes.find((route: RouteRecordRaw) => route.name === state.secondRouteName) as any).children
      return thirdRoute
    }
  },
  mutations: {
    setTopRouteName (state: StateValue, topRouteName = '') {
      state.topRouteName = topRouteName
    },
    setSecondRouteName (state: StateValue, secondRouteName = '') {
      state.secondRouteName = secondRouteName
    },
    setThirdRouteName (state: StateValue, thirdRouteName = '') {
      state.thirdRouteName = thirdRouteName
    }
  },
  actions: {
  },
  namespaced: true
}
